package com.presto.directo.mvvm.viewmodel

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.presto.directo.entity.WorkEntity
import com.presto.directo.net.getHttpMap
import com.presto.directo.net.sign
import com.presto.directo.utils.*

class WorkViewModel(application: Application) : BaseViewModel(application) {

    val infoLiveData = MutableLiveData<WorkEntity>()
    var education = -1
    var work_type = -1
    var salary = -1
    var work_experience = -1
    var payroll_cycle = -1
    var industry = -1

    fun getInfo() {
        start(onNext = {
            showProgress()
            getApiService().getWorkInfo(getHttpMap().sign(15)).getResultOrNull()?.let {
                education = it.education.toIntOrNull() ?: -1
                work_type = it.work_type.toIntOrNull() ?: -1
                industry = it.industry.toIntOrNull() ?: -1
                salary = it.salary.toIntOrNull() ?: -1
                work_experience = it.work_experience.toIntOrNull() ?: -1
                payroll_cycle = it.payroll_cycle.toIntOrNull() ?: -1
                infoLiveData.value = it
            }
        }, onComplete = {
            dismissProgress()
        })
    }

}